<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/inc/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息列表</title>
<%@ include file="/inc/head.jsp"%>
<script type="text/javascript" src="${ctx}/static/common/system/sys.js"></script>
<script type="text/javascript">
	var grid;
	$(function() {
		$("#addDialog").dialog("close");
		grid = $('#grid').datagrid({
			title : '',
			url : '${ctx}/sys/user/0/0?search.status_eq=blocked',
			striped : true,
			rownumbers : true,
			pagination : true,
			idField : 'id',
			sortName : 'createDate',
			sortOrder : 'desc',
			pageSize : 50,
			pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
			frozenColumns : [ [ {
				field : 'id',
				checkbox : true
			}, {
				width : '100',
				title : '登录名',
				field : 'username',
				sortable : true
			}, {
				width : '80',
				title : '姓名',
				field : 'fullName',
				sortable : true
			} ] ],
			columns : [ [ {
				width : '150',
				title : '创建时间',
				field : 'createDate',
				sortable : true,
				formatter : function(value) {
					if (value == null || value == '') {
						return '';
					}
					var dt;
					if (value instanceof Date) {
						dt = value;
					} else {
						dt = new Date(value);
					}
					return dt.format("yyyy-MM-dd"); //扩展的Date的format方法(上述插件实现)
				}
			}, {
				width : '150',
				title : '修改时间',
				field : 'createDate',
				sortable : true,
				formatter : function(value) {
					if (value == null || value == '') {
						return '';
					}
					var dt;
					if (value instanceof Date) {
						dt = value;
					} else {
						dt = new Date(value);
					}
					return dt.format("yyyy-MM-dd"); //扩展的Date的format方法(上述插件实现)
				}
			}, {
				title : '操作',
				field : 'action',
				width : '90',
				formatter : function(value, row) {
					var str = '';
					str += user.delBtn(row.id);
					str += user.editBtn(row.id);
					return str;
				}
			} ] ],
			toolbar : '#toolbar'
		});
		user = {
			delBtn : function(id) {
				return sy
						.formatString(
								'<a href="javascript:void(0);" onclick="user.del(\'{0}\');">删除</a>',
								id);
			},
			editBtn : function(id) {
				return sy
						.formatString(
								'| <a href="javascript:void(0);" onclick="user.edit(\'{0}\');">编辑</a>',
								id);
			},
			remove : function() {
				var ids = [];
				var rows = $("#grid").datagrid('getSelections');
				if (rows.length > 0) {
					$.messager.confirm('你确定永久删除该数据吗?', function(r) {
						if (r) {
							for ( var i = 0; i < rows.length; i++) {
								ids.push(rows[i].id);
							}
							$.ajax({
								url : "${ctx}/sys/user/deleteByIds",
								type : 'post',
								dataType : 'json',
								data : {
									ids : ids.join(',')
								},
								cache : false,
								success : function(d) {
									if (d.success) {
										$.sys.user.tip(d.msg);
										$.sys.user.reloadTable();
										$("#grid").datagrid('unselectAll');
										ids = '';
									}
								}
							});
						}
					});
				} else {
					$.sys.user.tip("请选择需要删除的数据");
				}
			},
			create : function() {
				$("#addDialog").dialog('open');
			},
			edit : function(id) {
				var dialog = parent.sy.modalDialog({
					title : '编辑用户信息',
					url : "${ctx}/sys/user/update/" + id,
					width : 400,
					height : 300,
					buttons : [ {
						text : '编辑',
						iconCls : 'icon-save',
						handler : function() {
							dialog.find('iframe').get(0).contentWindow
									.submitForm(dialog, grid, parent.$);
						}
					} ]
				});
			}
		};
	});
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<div style="padding: 0 0 0 7px; color: #333;">
			<form id="searchForm">
				<table>
					<tr>
						<td>登录名</td>
						<td><input name="search.username_like" style="width: 80px;" /></td>
						<td>姓名</td>
						<td><input name="search.fullName_like" style="width: 80px;" /></td>
						<td>创建时间</td>
						<td><input name="search.createDate_gt" class="Wdate"
							onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
							readonly="readonly" style="width: 120px;" />-<input
							name="search.createDate_lt" class="Wdate"
							onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
							readonly="readonly" style="width: 120px;" /></td>
						<td><a href="javascript:void(0);" class="easyui-linkbutton"
							data-options="iconCls:'icon-search',plain:true"
							onclick="grid.datagrid('load',$.sys.user.serializeObject($('#searchForm')));">过滤</a><a
							href="javascript:void(0);" class="easyui-linkbutton"
							data-options="iconCls:'icon-cologne-zoom',plain:true"
							onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div>
			<a href="javascript:void(0);" class="easyui-linkbutton"
				data-options="iconCls:'icon-add',plain:true"
				onclick="user.create();">添加</a> <a href="javascript:void(0);"
				class="easyui-linkbutton"
				data-options="iconCls:'icon-edit',plain:true" onclick="">编辑</a> <a
				href="javascript:void(0);" class="easyui-linkbutton"
				data-options="iconCls:'icon-remove',plain:true"
				onclick="user.remove();">批量删除</a>
		</div>
	</div>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>